package river_city_ransom.implementations;

import exceptions.ComposantError;
import river_city_ransom.services.Objet;
import river_city_ransom.services.Position;
import river_city_ransom.types.ObjetNom;


public class Objet_I extends Equipable_I implements Objet {
	protected ObjetNom nom;
	protected int valeur;
	protected int bonusDeForce;
	protected boolean estMarchandable;
	
	public Objet_I(ObjetNom n) {
		super();
		try {
			init(n);
		}
		catch(ComposantError e) {
			System.err.println(e.getMessage());
		}
	}
	
	@Override
	public boolean equals(Object o) {
		if(!(o instanceof Objet)) {
			return false;
		}
		if(!super.equals(o)) {
			return false;
		}
		if(nom() != ((Objet) o).nom()) {
			return false;
		}
		if(valeur() != ((Objet) o).valeur()) {
			return false;
		}
		if(bonusDeForce() != ((Objet) o).bonusDeForce()) {
			return false;
		}
		if(estMarchandable() != ((Objet) o).estMarchandable()) {
			return false;
		}
		return true;
	}
	
	/** ________________________________________________________ CONSTRUCTORS */
	@Override
	public void init(ObjetNom n) throws ComposantError {
		// Equipable
		estPorte = false;
		estJete = 0;
		position = new Position_I(0, 0, 0);
		// Objet
		nom = n;
		switch(nom) {
			case CINQUANTE_CENTIME :
				dimensions = new Dimensions_I(5, 5, 1);
				valeur = 50;
				bonusDeForce = 0;
				break;
			case UN_DOLLAR :
				dimensions = new Dimensions_I(5, 5, 1);
				valeur = 100;
				bonusDeForce = 0;
				break;
			case CHAINE_DE_VELO :
				dimensions = new Dimensions_I(15, 5, 5);
				valeur = 0;
				bonusDeForce = 10;
				break;
			case POUBELLE_METALLIQUE :
				dimensions = new Dimensions_I(10, 15, 10);
				valeur = 0;
				bonusDeForce = 15;
				break;
		}
		estEquipable = bonusDeForce > 0 ? true : false;
		estMarchandable = !estEquipable;
	}
	
	/** _________________________________________________________ OBSERVATORS */
	@Override
	public ObjetNom nom() {
		return nom;
	}
	
	@Override
	public int valeur() {
		return valeur;
	}
	
	@Override
	public int bonusDeForce() {
		return bonusDeForce;
	}
	
	@Override
	public boolean estMarchandable() {
		return estMarchandable;
	}
	
	/** ___________________________________________________________ OPERATORS */
	@Override
	public void deplacer(Position p) throws ComposantError {
		position = p;
	}
}
